package me.zhengjie.config;

import com.ibeetl.starter.BeetlSqlCustomize;
import javax.sql.DataSource;
import org.beetl.sql.core.Interceptor;
import org.beetl.sql.ext.spring4.BeetlSqlDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author daihy
 */
@Configuration
@Import(DataSourceAutoConfiguration.class)
public class BeetlSQLConfig {

  @Bean
  public BeetlSqlDataSource beetlSqlDataSource(DataSource dataSource) {
    BeetlSqlDataSource source = new BeetlSqlDataSource();
    source.setMasterSource(dataSource);
    return source;
  }

  @Bean
  public BeetlSqlCustomize beetlSqlCustomize() {
    return (sqlManager) -> {
      sqlManager.setInterceptors(new Interceptor[]{});
    };
  }
}
